/**
 *	---------------------------------------------------------------------------
 *	COMP 6231/FALL 2013
 *	Assignment - 02
 *	@author Talha Rahman (1296884)
 *	---------------------------------------------------------------------------
 *	The CORBAService class provides the necessary functions for the CORBA services.
 *
 *	@see {@link StationServerCORBAInterface}
 *	  
 */
package ca.concordia.comp6231.corba;

import java.io.PrintWriter;

import org.omg.CORBA.ORB;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;

import ca.concordia.comp6231.frontend.FrontEnd;

public class CORBAService extends Thread {

	private FrontEnd server;
	private String[] args;

	public CORBAService(FrontEnd server, String[] args) {
		this.server = server;
		this.args = args;
	}

	@Override
	public void run() {
		try {
			ORB orb = ORB.init(args, null);
			POA rootPOA = POAHelper.narrow(orb
					.resolve_initial_references("RootPOA"));

			byte[] id = rootPOA.activate_object(server);
			org.omg.CORBA.Object ref = rootPOA.id_to_reference(id);

			String ior = orb.object_to_string(ref);
			System.out.println(ior);

			PrintWriter file = new PrintWriter("FE.txt");
			file.println(ior);
			file.close();

			rootPOA.the_POAManager().activate();
			orb.run();
		} catch (Exception e) {

		}

	}

}
